package com.sq.partner.manager.common;

/**
 * 结果类 ,保持和验证一致
 * @author sankun
 *
 */
public class Result {
	private static final String RESULT_FAIL  = "fail";
	private static final String RESULT_SUCCESS  = "success";
	private static final String RESULT_ERROR  = "error";
	private String result;//结果
	private String message;//消息
	private Object data;//数据
	private Result(){};
	
	private Result(String result,String message,Object data){
		this.result = result;
		this.message = message;
		this.data = data;
	}
	
	public String getResult() {
		return result;
	}
	public String getMessage() {
		return message;
	}
	
	/**
	 * 返回带有数据及消息的成功result
	 * @param message 消息
	 * @param data
	 * @return
	 */
	public static Result success(String message,Object data){
		return new Result(RESULT_SUCCESS,message,data);
	}
	
	/**
	 * 返回带有数据无消息的成功result
	 * @param message 消息
	 * @param data
	 * @return
	 */
	public static Result success(Object data){
		return new Result(RESULT_SUCCESS,null,data);
	}
	
	/**
	 * 返回数据
	 * @param message
	 * @return
	 */
	public static Result data(Object data){
		return new Result(null,null,data);
	}
	
	/**
	 * 返回成功
	 * @param message
	 * @return
	 */
	public static Result success(String message){
		return new Result(RESULT_SUCCESS,message,null);
	}
	/**
	 * 返回成功加带数据
	 * @param message
	 * @param data
	 * @return
	 */
	public static Result successAndData(String message,Object data){
		return new Result(RESULT_SUCCESS,message,data);
	}
	
	/**
	 * 返回失败
	 * @param message
	 * @return
	 */
	public static Result error(String message){
		return new Result(RESULT_ERROR,message,null);
	}
	
	/**
	 * 返回带消息的异常
	 * @param message
	 * @return
	 */
	public static Result fail(String message){
		return new Result(RESULT_FAIL,message,null);
	}
	
	/**
	 * 返回异常
	 * @param message
	 * @return
	 */
	public static Result fail(){
		return new Result(RESULT_FAIL,null,null);
	}
	
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	
}
